<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
		<meta charset="utf-8" />
	<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="#">实习单位管理</a></li>
    <li><a href="#">实习单位信息</a></li>
    </ul>
    </div>
    <div class="rightinfo">
    <div class="tools">
    <form id="searchForm" class="form-search" action="enterpriseinfo/enterpriseinfo_page_list.do" method="post">
    	<ul class="seachform1">
    		<li>选择省份：</li>  
    	    <li>
    		  <select id="dpselect" name="TheProvince" class="chosen-select col-xs-10 col-sm-5" onchange="selectChanged();">
						<option value="0" > -- 全部 -- </option>
						<c:forEach items="${provinceList}" var="province">
							<option value="${province.provinceId }" <c:if test="${province.provinceId == TheProvince }">selected</c:if> >${province.provinceName }</option>
						</c:forEach>
					</select>
    	</li>
	<li>选择城市：</li>  
    	    <li>
    		  <select id="TheCity"  name="TheCity" class="chosen-select col-xs-10 col-sm-5" >
						<option value="0" > -- 全部 -- </option>
						<c:forEach items="${cityList}" var="city">
							<option value="${city.cityId }" <c:if test="${city.cityId == TheCity }">selected</c:if> >${city.cityName }</option>
						</c:forEach>
					</select>
    	</li>
		<li><input name="Name" value="${Name}"   type="text" class="scinput1" placeholder="输入企业名称" /></li>
		<li><input name="" type="button" id="btnSearch" class="scbtn" value="查询"/></li>  
		<div class="clearfix"></div>	<input type="hidden" name="pageNumber" value="1" /> 
		</ul>	
		</form>
    	<ul class="toolbar">
    	<c:if test="${ userRole <=3}">
        <li class="click add"><span><img src="images/t01.png" /></span>添加</li>
        </c:if>
        <!--<li class="click"><span><img src="images/t02.png" /></span>修改</li>
        <li><span><img src="images/t03.png" /></span>删除</li>
        <li><span><img src="images/t04.png" /></span>统计</li>-->
        </ul>
    </div>
    <table class="tablelist">
    	<thead>
    	<tr>
    	<th>序号</th>
        <th>企业名称</th>
        <th>联系人</th>
		<th>联系电话</th>
       <th>企业地址</th>
       <th>操作</th>
      </tr>
        </thead>
        <tbody>
        <c:forEach items="${enterpriseinfoList}" var="enterpriseinfo"  varStatus="status">
      <tr>
      <td>${ status.index + 1}</td>
      <td>${enterpriseinfo.name}</td>
     <td>${enterpriseinfo.theContact}</td>
     <td>${enterpriseinfo.theContactPhone}</td>
     <td>${enterpriseinfo.theAddress}</td>
		<td> <c:if test="${ userRole <=3}"><a onclick="edit('${enterpriseinfo.id}');">编辑</a>&nbsp;&nbsp;&nbsp;&nbsp;<a  onclick="deleteEnterpriseinfo('${enterpriseinfo.id}');">删除</a></c:if></td>
      </tr> 
      </c:forEach>
        </tbody>
    </table>
    <div class="pagin">
    	<%@ include file="page.jsp"%>
    </div>
    </div>
    <script src="js/jquery-1.7.2.js"></script>
    <script src="layer/layer.js"></script>
    <script type="text/javascript">
    $('.tablelist tbody tr:odd').addClass('odd');
	$( "#btnSearch" ).on('click', function(e) {
		$("#searchForm").submit();
	});
	function GoToPage(toPage,totalPage) {
	    if(toPage<=0) return;
	    if(toPage>totalPage) return;
	    $("input[name='pageNumber']").val(toPage);
	    $("#searchForm").submit();
	};
	function selectChanged() {
		 var ele=document.getElementById('dpselect');
  	  	var index=ele.selectedIndex;
  	 	 var val=ele.options[index].value;
  	 	$.ajax({
			type: "POST",
			url: "enterpriseinfo/province.do",
			data: { ProvinceId : val},
			async: true,
			dataType: "json",
			success: function(data) {
				$("#TheCity").empty();
				var all="<option value='0' >-- 全部 -- </option>";
				for(var i in data.cityList){  
					var $str = "<option value="+data.cityList[i].cityId +">"+data.cityList[i].cityName +"</option>";
					$("#TheCity").append($str);  	 
				}
				$("#TheCity").append(all);
			}
			})
			}
	function closeAll() {
		layer.alert('添加成功!', {
			skin : 'layer-ext-moon'
		}, function() {
			layer.closeAll(); 
			  location.reload();
		}); 
	}
	function close() {
		layer.alert('修改成功!', {
			skin : 'layer-ext-moon'
		}, function() {
			layer.closeAll(); 
			  location.reload();
		}); 
	}
	
	$(".add").click(
	function  () {
		layer.open({
  type: 2,
  closeBtn: 2,
  title: '添加单位信息',
  shadeClose: true,
  shade: 0.8,
  area: ['600px', '500px'],
  content: 'enterpriseinfo/add_enterpriseinfo.do',
	  end: function () {
	      location.reload();
	  }
});
	}
	);
	function  edit(id) {
		layer.open({
  type: 2,
  closeBtn: 2,
  title: '编辑单位信息',
  shadeClose: true,
  shade: 0.8,
  area: ['600px', '500px'],
  content: 'enterpriseinfo/edit_enterpriseinfo.do?Id='+id,
	  end: function () {
	      location.reload();
	  }
});
	}
	function deleteEnterpriseinfo(Id) {
		$.ajax({
			type: "GET",
			url: "enterpriseinfo/delete.do?Id="+Id,
			async: true,
			dataType: "json",
			success: function(data) {
				if("success" == data.result){
					layer.alert('删除成功!', {
			            skin: 'layer-ext-moon' 
					}, function(){
					 location.reload();
					 });
					}else {
						layer.alert('删除失败!', {
				            skin: 'layer-ext-moon' 
				        });
						}
				}
			})
	};
	
	</script>
</body>